<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>资方逾期异常记录表 管理</title>
    <style type="text/css">
    </style>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
            <div class="fieldset1 clearFix">
                <div class="fieldBox">
                    <div class="label">支付表号</div>
                    <div class="field">
                        <input name="paySchNo" id="paySchNo" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                
                <div class="fieldBox">
                    <div class="label">承租人</div>
                    <div class="field">
                        <input name="cstNm" id="cstNm" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                
                 <div class="fieldBox">
                    <div class="label">更新日期</div>
                    <div class="field">
                        <input name="mdfTm" id="mdfTm"  ligerui="width: 120" type="text" class="ui-datepicker" value="">
                    </div>
                </div>
                <div class="fieldBox col_33">
                    <div class="label">异常原因</div>
                    <div class="field">
                        <select name="errorCode" id="errorCode">
                            <option value="" selected="selected">--请选择--</option>
                                <option value="1">逾期记录不存在</option>
                                <option value="2">逾期本金不一致</option>
                                <option value="3">资方罚息小于0</option>
                                <option value="4">逾期记录更新失败</option>

                        </select>
                    </div>
                </div>
                <div class="clearFix"></div>
                <div class="btnsBox">
                    <span id="searchBtn" class="sq-button sq-button-round">查询</span>
                    <span id="clearBtn" class="sq-button sq-button-round">清空</span>
                    <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
                </div>
            </div>
        </form>
    </div>
    <div id="ligergrid1" class="sq-grid"></div>
</div>

<script type="text/javascript">
    var grid = null,callback=null;
    $(function () {
        grid = $("#ligergrid1").ligerGrid({
            url: '<%=path%>/capital/capOvdErrLog/initList.do',
            method: 'get',
            columns: [
                
                {display: '支付表号', name: 'paySchNo', minWidth: 150, align: 'center', enabledSort: false},
                {display: '承租人', name: 'cstNm', minWidth: 100, align: 'center', enabledSort: false},
                {display: '更新日期', name: 'mdfTm', minWidth: 100, align: 'center', enabledSort: false,render:renderDate},

                {display: '资方逾期日期', name: 'ovdDt', minWidth: 100, align: 'center', enabledSort: false,render:renderDate},
                //{display: '数据状态:0.待处理 1.处理中 2.已处理', name: 'dataStsCdNm', minWidth: 100, align: 'left', enabledSort: false},
                {
                    display: '资方逾期本金(元)', name: 'ovdPrincAmt', width: 100, align: 'center', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.ovdPrincAmt / 100);
                    }
                },
                {
                    display: '资方逾期利息(元)', name: 'ovdInterestAmt', width: 100, align: 'center', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.ovdInterestAmt / 100);
                    }
                },
                {
                    display: '资方罚息(元)', name: 'ovdPenaltyAmt', width: 100, align: 'center', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.ovdPenaltyAmt / 100);
                    }
                },
                {
                    display: '处理状态', name: 'dataStsCd', width: 100, align: 'center', enabledSort: false,
                    render: function (rowdata, index, value) {
                        if(rowdata.dataStsCd=='0'){
                            return "未处理"
                        }else if(rowdata.dataStsCd=='2'){
                            return "已更新"
                        }else if(rowdata.dataStsCd=='3'){
                            return "已忽略"
                        }
                    }
                },
                {
                    display: '异常原因', name: 'errorCode', width: 200, align: 'center', enabledSort: false,
                    render: function (rowdata, index, value) {
                        var code = rowdata.errorCode;
                        if(code != null && code != ''){
                            var arrayCode = code.split('#');
                            var error = '';
                            for(var i = 0 ;i < arrayCode.length; i++){
                                if(arrayCode[i] == '1'){
                                    error = '逾期记录不存在 ';
                                }else if(arrayCode[i] == '2'){
                                    error += ' 逾期本金不一致';
                                }else if(arrayCode[i] == '3'){
                                    error += ' 资方罚息小于0';
                                }else if(arrayCode[i] == '4'){
                                    error += ' 逾期记录更新失败 ';
                                }
                            }
                            return error;
                        }else{
                            return '';
                        }
                    }
                },
                {display: '操作', name: '', width: 200, align: 'center', enabledSort: false,render:renderHandle},
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            //isScroll: false,
            checkbox: true,
            rownumbers: true,
            allowUnSelectRow: true,
            alternatingRow: false
            /* onRenderComplete: function () {
             iframeResize ();
             } */
        });
        grid.setHeight(100);

        $("#searchBar").ligerForm();

        $("#pageloading").hide();

        /* 查询 */
        $("#searchBtn").click(function (event) {
            var form = liger.get("searchBar");
            var data = form.getData();
            for (name in data) {
                grid.setParm(name, data[name]);
            }
            grid.reload();
        });

        /* 清空 */
        $("#clearBtn").click(function (event) {
            var errorCode = liger.get("errorCode");
            errorCode.selectValue(" ");
            clearLigerForm("searchBar");
        });
        
        callback = function () {
            grid.reload();
        };

        /* 新增 */
        $("#addBtn").click(function (event) {
            $.ligerDialog.open({
                width: 550,
                height: 500,
                title: '新增资方逾期异常记录表',
                url:'<%=path%>/capital/capOvdErrLog/toAddPage.do'
            });
            //Add_navTab("CapOvdErrLog_1", "新增资方逾期异常记录表", '<%=path%>/capital/capOvdErrLog/toAddPage.do', callback);
        });

        /* 修改 */
        $("#changeBtn").click(function (event) {
            var selectedRows = grid.getSelectedRows();
            if (selectedRows.length != 1) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
                return;
            }
            var _id=selectedRows[0].id;
            $.ligerDialog.open({
                width: 550,
                height: 500,
                title: '修改资方逾期异常记录表',
                url:'<%=path%>/capital/capOvdErrLog/toModifyPage.do?id='+_id
            });
            //Add_navTab('CapOvdErrLog_2'+_id, "修改资方逾期异常记录表", '<%=path%>/capital/capOvdErrLog/toModifyPage.do?id='+_id, callback);
        });

        /* 删除 */
        $("#delBtn").click(function () {
            var selectedRows = grid.getSelectedRows();
            if (selectedRows.length == 0) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_MORE_ROW, SQ_type: "warning"});
                return;
            }
            var _ids = [];
            for (var index in selectedRows) {
                _ids.push(selectedRows[index].id);
            }

            $.ligerDialog.confirm(LogUtils.LOG_CMM_DELETE_CONFIRM, function (flag) {
                if (flag == false)return;
                var wait_dialog;
                $.ajax({
                    type: 'post',
                    dataType: 'json',
                    data: {ids: JSON.stringify(_ids)},
                    url: '<%=path%>/capital/capOvdErrLog/removeByIds.do',
                    beforeSend: function () {
                        wait_dialog = $.ligerDialog.SQalert({
                            content: LogUtils.LOG_CMM_DATA_LOADING,
                            SQ_type: "waitting"
                        });
                    },
                    success: function (msg) {
                        wait_dialog.close();
                        if (msg.success == 1) {
                            $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                            grid.reload();
                        } else {
                            $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                        }
                    }
                });
            });
        });

    });

    //忽略数据
    function ignoreData(id){
        if(!id)return;
        $.ligerDialog.confirm("是否确认忽略?", function (flag) {
            if(flag == false)return;
            var wait_dialog;
            $.ajax({
                type: 'post',
                dataType:'json',
                data:{id:id},
                url: '<%=path%>/capital/capOvdErrLog/ignoreData.do',
                beforeSend: function(){
                    wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
                },
                success:function(msg){
                    wait_dialog.close();
                    if(msg.success == 1){
                        $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
                        grid.reload();
                    }else{
                        $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
                    }
                }
            });
        });
    }
    //更新数据
    function updateData(id,ovdPenaltyAmt,paySchId,marks){
        ovdPenaltyAmt=ovdPenaltyAmt.replace(/,/g,"")
        $.ligerDialog.open({
            width: 350,
            height: 200,
            title: '更新罚息金额',
            url: '<%=path%>/capital/capOvdErrLog/updateData.do?id='+id+'&ovdPenaltyAmt='+ovdPenaltyAmt+'&paySchId='+paySchId+'&marks='+marks
        });
    }
  //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
        }
        return dateStr;
    }
    function renderHandle(rowdata, index, value) {
        var dateStr = "";
        var currentStr = "";
        var date = new Date(rowdata.mdfTm);
        dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
        currentStr = DateUtils.formatDate( new Date(), DateUtils.YYYY_MM_DD);
        if(dateStr == currentStr &&  rowdata.dataStsCd == '0'){
            var h='<a  style="cursor:pointer;" href="javascript:;" onclick="ignoreData(';
            h+="'"+rowdata.id+"'";
            h+=')"><i class="sqBtnIco_1"></i>忽略 </a>';
            h+='<a  style="cursor:pointer;" href="javascript:;" onclick="updateData(';
            h+="'"+rowdata.id+"',"+"'"+rowdata.ovdPenaltyAmt+"',"+"'"+rowdata.paySchId+"',"+'1';
            h+=')"><i class="sqBtnIco_1"></i> 次日异常处理</a>';
            h+='<a  style="cursor:pointer;" href="javascript:;" onclick="updateData(';
            h+="'"+rowdata.id+"',"+"'"+rowdata.ovdPenaltyAmt+"',"+"'"+rowdata.paySchId+"',"+'2';
            h+=')"><i class="sqBtnIco_1"></i> 跨次日异常处理</a>';
            return h;
        }else{
            var h='<a  class="disabled" style="opacity: 0.2" href="javascript:;"><i class="sqBtnIco_1"></i>忽略 </a>';
            h+='<a  class="disabled" style="opacity: 0.2" href="javascript:;"><i class="sqBtnIco_1"></i> 次日异常处理</a>';
            h+='<a class="disabled"  style="opacity: 0.2" href="javascript:;"><i class="sqBtnIco_1"></i> 跨次日异常处理</a>';
            return h;
        }
    }

</script>

</body>
</html>
